HA$PBExportHeader$uo_busca_clientes.sru
forward
global type uo_busca_clientes from userobject
end type
type p_buscar from picture within uo_busca_clientes
end type
type gb_1 from groupbox within uo_busca_clientes
end type
type sle_texto from singlelineedit within uo_busca_clientes
end type
end forward

global type uo_busca_clientes from userobject
integer width = 1522
integer height = 212
long backcolor = 67108864
string text = "none"
long tabtextcolor = 33554432
long picturemaskcolor = 536870912
p_buscar p_buscar
gb_1 gb_1
sle_texto sle_texto
end type
global uo_busca_clientes uo_busca_clientes

type variables
datawindow dw
string columna,columna_integer,columna_label
end variables

forward prototypes
public subroutine wf_poner_titulo ()
public subroutine wf_sort ()
end prototypes

public subroutine wf_poner_titulo ();gb_1.text = 'Buscar por ' +columna_label
sle_texto.text = ''
dw.setfilter("")
dw.filter()
end subroutine

public subroutine wf_sort ();//Ordene el dw por la columna definida para que la busqueda sea mas efectiva

//if columna_integer = columna then
//	dw.SetSort("integer("+columna+") asc" )
//else	
//	dw.SetSort(columna+" asc" )
//end if
//	
//dw.Sort()
end subroutine

on uo_busca_clientes.create
this.p_buscar=create p_buscar
this.gb_1=create gb_1
this.sle_texto=create sle_texto
this.Control[]={this.p_buscar,&
this.gb_1,&
this.sle_texto}
end on

on uo_busca_clientes.destroy
destroy(this.p_buscar)
destroy(this.gb_1)
destroy(this.sle_texto)
end on

type p_buscar from picture within uo_busca_clientes
integer x = 27
integer y = 72
integer width = 73
integer height = 64
boolean originalsize = true
string picturename = "Find!"
boolean focusrectangle = false
end type

type gb_1 from groupbox within uo_busca_clientes
integer x = 5
integer width = 1495
integer height = 192
integer taborder = 10
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "MS Sans Serif"
long textcolor = 33554432
long backcolor = 67108864
string text = "Buscar por"
end type

type sle_texto from singlelineedit within uo_busca_clientes
event ue_keypress pbm_keyup
integer x = 119
integer y = 60
integer width = 1344
integer height = 92
integer taborder = 10
boolean bringtotop = true
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "MS Sans Serif"
long textcolor = 33554432
borderstyle borderstyle = stylelowered!
end type

event ue_keypress;//Busca sensitivamente dentro de una columna de tipo char()
//primero debe definir en el condstructor el dw y la columna a buscar

long is_linea
string buscar,ls_tipo,ls_col,ls_cad
int largo
ls_tipo = dw.Describe(columna+".coltype")
buscar = upper(Text)
largo = len(buscar)
//choose case  mid(ls_tipo,1,4) 
//		case 'char' 
//			is_linea = dw.find("upper(mid("+columna+",1,"+string(largo)+")) = '"+buscar+"'",1,dw.rowcount())
//		case 'deci'	
//			is_linea = dw.find("upper(mid(string("+columna+"),1,"+string(largo)+")) = '"+buscar+"'",1,dw.rowcount())
//		case 'long'	
//			is_linea = dw.find("upper(mid(string("+columna+"),1,"+string(largo)+")) = '"+buscar+"'",1,dw.rowcount())
//end choose			

//string ls_cad,ls_tipo,ls_col
if buscar = ""  then
		dw.SetFilter("")
else
		ls_col = dw.describe(columna+'.name')
		ls_tipo=dw.describe(ls_col+'.coltype')
		ls_cad = 'Upper(string('+ls_col+')) like "%'+Upper(buscar)+'%" '
		dw.SetFilter(ls_cad)	
end if
dw.filter()



//string ls_cad,ls_tipo,ls_col
//if cadena = ""  then
//		this.dw_1.SetFilter("")
//else
//		ls_col = this.dw_1.describe(columna+'.name')
//		ls_tipo=this.dw_1.describe(ls_col+'.coltype')
//		ls_cad = 'Upper(string('+ls_col+')) like "%'+Upper(cadena)+'%" '
//		this.dw_1.SetFilter(ls_cad)	
//end if
//this.dw_1.filter()

//dw.scrolltorow(is_linea)


end event

event constructor;//debe definir prinero el dw y la comuna a buscar
//llama al evento sort despues de termibnar el constructor
Post wf_sort()
Post wf_poner_titulo()
end event

